package uns.fit.gis.ui;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

import uns.fit.gis.MapDrawer;
import uns.fit.gis.Util;
import uns.fit.gis.mapdrawer.MapCanvas;

public class RouteAssistCanvas extends Canvas implements CommandListener {
	private Command backCommand;
	private MapDrawer midlet;
	private static Font font;
	
	public RouteAssistCanvas(MapDrawer midlet) {
		this.midlet = midlet;
		backCommand = new Command("Quay lại", Command.BACK, 1);
		addCommand(backCommand);
		setCommandListener(this);
		font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
	}
	
	protected void paint(Graphics g) {
		g.setFont(font);
		if(MapCanvas.alg != null) {
			String route = MapCanvas.alg.routeToString();
			g.setColor(221, 238, 187);
			g.fillRect(0, 0, getWidth(), getHeight());
			g.setColor(0, 0, 0);
			if(route != null) {
				
			}
		}
		Util.centerScreen(MapCanvas.currentX, MapCanvas.currentY);
		midlet.updateMapCanvas();
		g.drawImage(MapCanvas.imageMap, 0, 0, Graphics.TOP | Graphics.LEFT);
	}
	
	public void commandAction(Command command, Displayable displayable) {
		if(command == backCommand) {
			midlet.showMapCanvas();
		}
	}
}
